﻿/* 
 * Since 2008 - 2013
 */

package com.hh.bss.oa.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

import com.hh.bss.base.*;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.oa.dao.*;
import com.hh.bss.oa.entity.*;
import com.hh.bss.oa.service.*;
import com.hh.bss.oa.vo.query.*;
import com.hh.bss.util.*;




@Service
@Transactional
public class OaMeetingRoomTakingCancelServiceImpl extends BaseBusinessService<OaMeetingRoomTakingCancel,java.lang.Integer>  implements OaMeetingRoomTakingCancelService<OaMeetingRoomTakingCancel,java.lang.Integer>{

	private OaMeetingRoomTakingCancelDao oaMeetingRoomTakingCancelDao;
	private OaMeetingRoomTakingDao oaMeetingRoomTakingDao;
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setOaMeetingRoomTakingCancelDaoImpl(OaMeetingRoomTakingCancelDao dao) {
		this.oaMeetingRoomTakingCancelDao = dao;
	}
	public void setOaMeetingRoomTakingDaoImpl(OaMeetingRoomTakingDao dao) {
		this.oaMeetingRoomTakingDao = dao;
	}
	public EntityDao getEntityDao() {
		return this.oaMeetingRoomTakingCancelDao;
	}
	
	@Transactional(readOnly=true)
	public Page findPage(OaMeetingRoomTakingCancelQuery query) {
		return oaMeetingRoomTakingCancelDao.findPage(query);
	}
	@Override
	public boolean isTaskDay(Integer taskId, Date date) {
		// TODO Auto-generated method stub
		OaMeetingRoomTaking oaMeetingRoomTaking=(OaMeetingRoomTaking)oaMeetingRoomTakingDao.getById(taskId);
		
		Date orderDate = DateHelper.toDate(DateHelper.toString(oaMeetingRoomTaking.getOrderDate(), "yyyyMMdd"), "yyyyMMdd");
	    Date taskDate = DateHelper.toDate(DateHelper.toString(date, "yyyyMMdd"), "yyyyMMdd");
	    
	    int diffd=DateHelper.getDiffDay(taskDate, orderDate);
	    
	   // System.out.println(orderDate+"--"+taskDate+"--"+diffd+"--"+(diffd%7));
	    
	    if (oaMeetingRoomTaking.getPeriodType().intValue()==1){
	    	if (orderDate.equals(taskDate)) return true;
	    }else if (oaMeetingRoomTaking.getPeriodType().intValue()==2){
	    	if (orderDate.equals(taskDate)||orderDate.before(taskDate)) return true;
	    	
	    }else if (oaMeetingRoomTaking.getPeriodType().intValue()==3){
	    	if (diffd%7==0) return true;
	    }else if (oaMeetingRoomTaking.getPeriodType().intValue()==4){
	    	if (diffd%14==0) return true;
	    }
	    
		return false;
	}
	@Override
	public boolean hasCancel(Integer id,Integer taskId, Date date) {
		// TODO Auto-generated method stub
		List values = new ArrayList();
		values.add(id);
		values.add(taskId);
		values.add(date);
		List l2=getEntityDao().getHibernateTemplate().find("from OaMeetingRoomTakingCancel t where t.id<>? and t.taskId=? and t.meetingDate=? ",values.toArray());
		if (l2!=null&&l2.size()>0){
			return true;
		}
		return false;
	}
	
}
